package com.yida.gwj.basis.service.impl;

import com.yida.common.core.exception.ServiceException;
import com.yida.common.core.utils.DateUtils;
import com.yida.common.core.utils.StringUtils;
import com.yida.common.security.utils.SecurityUtils;
import com.yida.gwj.basis.domain.GwjInitBusinessCommunity;
import com.yida.gwj.basis.mapper.GwjInitBusinessCommunityMapper;
import com.yida.gwj.basis.service.IGwjInitBusinessCommunityService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 业务小区信息（基础数据管理模块）Service业务层处理
 *
 * @author lqq
 * @date 2022-11-15
 */
@Service
public class GwjInitBusinessCommunityServiceImpl implements IGwjInitBusinessCommunityService {

	@Resource
	private GwjInitBusinessCommunityMapper businessCommunityMapper;

	/**
	 * 新增业务小区信息（基础数据管理模块）
	 *
	 * @param businessCommunity 业务小区信息（基础数据管理模块）
	 * @return 结果
	 */
	@Override
	public int save(GwjInitBusinessCommunity businessCommunity) {
		businessCommunity.setCreateBy(SecurityUtils.getLoginUser().getSysUser().getRealName());
		businessCommunity.setCreateTime(DateUtils.getNowDate());
		return businessCommunityMapper.insert(businessCommunity);
	}

	/**
	 * 新增业务小区信息（基础数据管理模块）
	 *
	 * @param businessCommunities 业务小区信息（基础数据管理模块）
	 * @return 结果
	 */
	@Override
	public int saveBatch(List<GwjInitBusinessCommunity> businessCommunities) {
		return businessCommunityMapper.saveBatch(businessCommunities);
	}

	/**
	 * 修改业务小区信息（基础数据管理模块）
	 *
	 * @param businessCommunity 业务小区信息（基础数据管理模块）
	 * @return 结果
	 */
	@Override
	public int updateById(GwjInitBusinessCommunity businessCommunity) {
		businessCommunity.setUpdateBy(SecurityUtils.getLoginUser().getSysUser().getRealName());
		businessCommunity.setUpdateTime(DateUtils.getNowDate());
		return businessCommunityMapper.updateById(businessCommunity);
	}

	/**
	 * 获取业务信息
	 *
	 * @param businessCommunity 业务小区信息（基础数据管理模块）
	 * @return /
	 */
	@Override
	public GwjInitBusinessCommunity getOne(GwjInitBusinessCommunity businessCommunity) {
		return businessCommunityMapper.selectOne(businessCommunity);
	}

	/**
	 * 根据业务ID,业务状态获取业务信息
	 *
	 * @param bizId  业务ID
	 * @param status 状态
	 * @return /
	 */
	@Override
	public GwjInitBusinessCommunity getOne(Long bizId, String status) {
		GwjInitBusinessCommunity businessCommunity = new GwjInitBusinessCommunity();
		if (StringUtils.isNull(bizId) || StringUtils.isBlank(status)) {
			throw new ServiceException("请求参数有误[bizId,status]");
		}
		businessCommunity.setBizId(bizId);
		businessCommunity.setStatus(status);
		return businessCommunityMapper.selectOne(businessCommunity);
	}
	/**
	 * 根据业务小区ID获取业务信息
	 *
	 * @param bizCommunityId 业务小区ID
	 * @return /
	 */
	@Override
	public GwjInitBusinessCommunity getById(Long bizCommunityId) {
		return businessCommunityMapper.selectById(bizCommunityId);
	}

	/**
	 * 根据业务ID获取业务信息
	 *
	 * @param bizId 业务ID
	 * @return /
	 */
	@Override
	public GwjInitBusinessCommunity getOne(Long bizId) {
		GwjInitBusinessCommunity businessCommunity = new GwjInitBusinessCommunity();
		if (StringUtils.isNull(bizId)) {
			throw new ServiceException("请求参数有误[bizId]");
		}
		businessCommunity.setBizId(bizId);
		return businessCommunityMapper.selectOne(businessCommunity);
	}

	/**
	 * 获取业务信息列表
	 *
	 * @param businessCommunity 业务小区信息（基础数据管理模块）
	 * @return /
	 */
	@Override
	public List<GwjInitBusinessCommunity> getList(GwjInitBusinessCommunity businessCommunity) {
		return businessCommunityMapper.selectList(businessCommunity);
	}

	/**
	 * 根据业务ID,业务状态获取业务信息列表
	 *
	 * @param bizId  业务ID
	 * @param status 状态
	 * @return /
	 */
	@Override
	public List<GwjInitBusinessCommunity> getList(Long bizId, String status) {
		if (StringUtils.isNull(bizId) || StringUtils.isBlank(status)) {
			throw new ServiceException("请求参数有误[bizId,status]");
		}
		GwjInitBusinessCommunity businessCommunity = new GwjInitBusinessCommunity();
		businessCommunity.setBizId(bizId);
		businessCommunity.setStatus(status);
		return businessCommunityMapper.selectList(businessCommunity);
	}

	/**
	 * 根据业务ID获取业务信息列表
	 *
	 * @param bizId 业务ID
	 * @return /
	 */
	@Override
	public List<GwjInitBusinessCommunity> getList(Long bizId) {
		if (StringUtils.isNull(bizId)) {
			throw new ServiceException("请求参数有误[bizId]");
		}
		GwjInitBusinessCommunity businessCommunity = new GwjInitBusinessCommunity();
		businessCommunity.setBizId(bizId);
		return businessCommunityMapper.selectList(businessCommunity);
	}

	/**
	 * 根据业务ID删除业务小区
	 *
	 * @param bizId 业务ID
	 * @return /
	 */
	@Override
	public int deleteByBizId(Long bizId) {
		if (StringUtils.isNull(bizId)) {
			throw new ServiceException("请求参数有误[bizId]");
		}
		return businessCommunityMapper.deleteByBizId(bizId);
	}
}
